package org.meichao.demo.service;

import com.alibaba.fastjson.JSONObject;
import org.meichao.demo.service.factory.BadgeFactory;
import org.meichao.demo.service.strategy.BadgeStrategy;
import org.meichao.utils.RespInfoUtils;
import org.meichao.utils.vo.RespInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Service
public class BadgeService {

    private final static Logger LOGGER = LoggerFactory.getLogger(BadgeService.class);

    @Resource
    private BadgeFactory badgeFactory;

    public RespInfo getBadgeInfo(String agentId, String badgeType){
        String uuid = UUID.randomUUID().toString();
        LOGGER.info("------获取徽章信息 入参，uuid,{},agentId:{},badgeType:{}", uuid, agentId, badgeType);
        List<JSONObject> badgeInfo = new ArrayList<>();
        //查询全部徽章,循环调用所有实现类
        if ("".equals(badgeType)) {
            for (BadgeStrategy badgeStrategy : badgeFactory.getAllStrategy()) {
                List<JSONObject> badgeInfoTemp = badgeStrategy.getBadgeInfo(agentId, badgeType);
                badgeInfo.addAll(badgeInfoTemp);
            }
            return RespInfoUtils.create().respSuccess(badgeInfo).toRespInfo();
        }

        badgeInfo = badgeFactory.getBadgeStrategy(badgeType).getBadgeInfo(agentId, badgeType);

        return RespInfoUtils.create().respSuccess(badgeInfo).toRespInfo();
    }
}
